/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;

import java.awt.Color;
import java.awt.Graphics;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;

/**
 *
 * @author kevin
 */
public class GraphicPanel{
    XYDataset xydataset;
    GraphicPanel()
    {
       // super();
        //this.setVisible(true);
        //this.setSize(100, 100);
        
        //xydataset = createDataset();
    }
    public  void createDataset(double[] fpr,double[] tpr)

{
        XYSeries xyseries = new XYSeries("ROC Curve"); //先产生XYSeries 对象
        xyseries.add(0, 0);
        for(int i=0;i<tpr.length;i++)
        {
            xyseries.add(fpr[i], tpr[i]);
        }
        XYSeries diagonal = new XYSeries("Diangonal");
        diagonal.add(0D,0D);
        diagonal.add(1D, 1D);
        XYSeriesCollection xyseriescollection = new XYSeriesCollection(); //再用XYSeriesCollection添加入XYSeries 对象
        xyseriescollection.addSeries(xyseries);
        xyseriescollection.addSeries(diagonal);
//        xyseriescollection.addSeries(xyseries1);
//        xyseriescollection.addSeries(xyseries2);
        xydataset = xyseriescollection;
    }


    //由ChartFactory 产生 JFreeChart 对象

public  JFreeChart createChart()
{
    JFreeChart jfreechart = ChartFactory.createXYLineChart("ROC CURVE",
    "False Positive Rate",
    "True Positive Rate",
    xydataset,
    PlotOrientation.VERTICAL,
    true,
    true,
    false);

    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot)jfreechart.getPlot(); //获得 plot：XYPlot！！
    xyplot.setBackgroundPaint(Color.lightGray); //设定图表数据显示部分背景色
    xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); //设定坐标轴与图表数据显示部分距离
    xyplot.setDomainGridlinePaint(Color.white); //网格线颜色
    xyplot.setRangeGridlinePaint(Color.white);
    //获得 renderer 注意这里是XYLineAndShapeRenderer ！！
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
    xylineandshaperenderer.setShapesVisible(true); //数据点可见
    xylineandshaperenderer.setShapesFilled(true); //数据点被填充即不是空心点
    NumberAxis numberaxis = (NumberAxis)xyplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}
}
